<?php


namespace App\Http\Controllers\Wechat;

use App\Http\Controllers\Controller;
use Monolog\Logger;
use Yansongda\Pay\Pay;

class PayController extends Controller
{


    public function wechat_pay($notify)
    {

        $config = $this->wx_config('wechat_pay');
        //设置微信授权回调地址
        $config['notify_url'] = env('APP_URL') . '/api/Mini/order/pay_notify';

        if (app()->environment() !== 'production') {
            $config['log']['level'] = Logger::DEBUG;
        } else {
            $config['log']['level'] = Logger::WARNING;
        }
        // 调用 Yansongda\Pay 来创建一个微信支付对象
        return Pay::wechat($config);

    }

    /**
     * Notes: 测试微信支付
     * User: lstink
     * Date: 2021/3/9
     * Time: 5:10 下午
     */
    public function pay()
    {
        $order = [
            'out_trade_no' => time(), //商户订单号
            'body' => 'subject-测试', //商品描述
            'total_fee' => '1', //订单总金额，单位为分
            'openid' => 'ojnPC4qMwkCEMS3--6WzEwH84Pvc', //openid
            'sub_mch_id' => '1602262945' //子商户id
        ];

        $result = app('wechat_server')->miniapp($order);
        dd($result);
    }

    /**
     * Notes: 付款到零钱
     * User: lstink
     * Date: 2021/3/9
     * Time: 6:32 下午
     */
    public function transfer()
    {
        $order = [
            'partner_trade_no' => '',              //商户订单号
            'openid' => '',                        //收款人的openid
            'check_name' => 'NO_CHECK',            //NO_CHECK：不校验真实姓名\FORCE_CHECK：强校验真实姓名
            // 're_user_name'=>'张三',              //check_name为 FORCE_CHECK 校验实名的时候必须提交
            'amount' => '1',                       //企业付款金额，单位为分
            'desc' => '帐户提现',                  //付款说明
        ];

        $result = app('wechat_pay')->transfer($order);
    }
}
